package com.weihuachao.repair;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lidroid.xutils.http.RequestParams;
import com.weihuachao.entity.Result;
import com.weihuachao.entity.User;
import com.weihuachao.https.BasicRequestCallBck;
import com.weihuachao.https.XUtils;

/**
 * Created by Virgo on 2016/7/30.
 */
public class RegisterActivity extends Activity {
    private Button cancel;
    private Button register;
    private EditText account;
    private EditText re_pass;
    private EditText pass;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register);
        XUtils.init(this);
        cancel = (Button) findViewById(R.id.Cancel_regeister);
        register = (Button) findViewById(R.id.regeister);
        account = (EditText) findViewById(R.id.re_username);
        pass = (EditText) findViewById(R.id.re_password);
        re_pass = (EditText) findViewById(R.id.rere_password);

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if ((re_pass.getText().toString().equals(pass.getText().toString())) && account.getText().length() > 5 && account.getText().length() < 12 && pass.getText().length() > 5 && pass.getText().length() < 20) {
                    RequestParams params = new RequestParams();
                    params.addBodyParameter("user.phone", account.getText().toString());
                    params.addBodyParameter("user.pwd", pass.getText().toString());
                    XUtils.send(XUtils.REGISTER, params, new BasicRequestCallBck<Result<Boolean>>() {
                        @Override
                        public void success(Result<Boolean> data) {
                            if (data.state == 1) {
                                Toast.makeText(RegisterActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                } else {
                    Toast.makeText(RegisterActivity.this, "帐号为6-11位，密码不一致", Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}
